 #include <stdio.h>

int Count_Digit ( const int N, const int D );

int main()
{
    int N, D;
	
    scanf("%d %d", &N, &D);
    printf("%d\n", Count_Digit(N, D));
    return 0;
}
 int Count_Digit(const int N,const int D)
 {
 	int a=N,num=0;
 	if(a<0)
 	  a=-a;
 	if(a==0)
 	  if(D==0)
 	   return 1;
 	  else  return 0;
 	  while(a!=0)
 	   { 
 	     if(a%10==D)
 	      num++;
 	      a=a/10; 
		}
	return num;
 }
